<template>
  <div id="root">
    <div id="left">
      <el-card>
        <h2>接收到的求职者简历</h2>
        <el-collapse v-model="activeNames" @change="handleChange">
          <template v-for="(job, index) in jobsWithResumes" :key="job.id">
            <el-collapse-item :name="index">
              <template #title>
                <div class="job-title">
                  <div style="font-size: 1.8em">{{ job.name }}</div>
                  <el-tag type="info"
                    >收到{{ job.jobResume.length }}条简历</el-tag
                  >
                </div>
              </template>
              <template
                v-for="resume in job.jobResume"
                :key="resume.sender.username"
              >
                <div class="resume-row">
                  <div>
                    <img
                      :src="resume.sender.avatarUrl"
                      width="80"
                      height="80"
                      style="border-radius: 40px"
                    />
                  </div>
                  <div class="resume-row-mid">
                    <div>
                      求职者：<span style="font-size: 1.6em">{{
                        resume.sender.name
                      }}</span>
                    </div>
                    <div>在{{ dts(resume.sendTime) }}之前投递</div>
                  </div>
                  <div>
                    <el-button
                      type="primary"
                      @click="selectEe(resume.resumeUrl)"
                      icon="el-icon-search"
                      >预览/下载简历</el-button
                    >
                  </div>
                </div>
              </template>
              <template v-if="!job.jobResume.length">
                <el-empty
                  :image-size="100"
                  description="暂无求职者投递简历"
                ></el-empty>
              </template>
            </el-collapse-item>
          </template>
        </el-collapse>
      </el-card>
    </div>
    <div id="right">
      <el-card>
        <h2>接收到的留言</h2>
        <template v-for="employee in employees" :key="employee.username">
          <div class="resume-row">
            <div>
              <img :src="employee.avatarUrl" class="avatar" />
            </div>
            <div>{{ employee.name }}</div>
            <div>
              <el-button type="primary" @click="showChatDialog(employee.username, employee.name, employee.avatarUrl)">与他沟通</el-button>
            </div>
          </div>
        </template>
      </el-card>
    </div>
  </div>
</template>

<script>
import mitter from '../../../plugins/mitter'
import dts from "../../../utils/dateTimeToStupid";
export default {
  data() {
    return {
      jobsWithResumes: [],
      employees: [],
      username: "",
      activeNames: [],
    };
  },
  methods: {
    selectEe(url) {
      window.open(url);
    },
    handleChange() {
      // console.log(val);
    },
    dts: dts,
    showChatDialog(username, name, avatarUrl) {
      const payload = {
        username: username,
        nickname: name,
        avatarUrl: avatarUrl
      }
      mitter.emit('showChatDialog', payload)
    }
  },
  created() {
    this.username = sessionStorage.getItem("username");
    this.axios
      .get("/employer/job-resume?username=" + this.username)
      .then((res) => {
        if (res.data.code == 200) {
          this.jobsWithResumes = res.data.data;
        }
      });
    this.axios
      .get("/employer/list-have-talk?username=" + this.username)
      .then((res) => {
        if (res.data.code == 200) {
          this.employees = res.data.data;
        }
      });
  },
};
</script>

<style scoped>
#root {
  display: flex;
  width: 1300px;
  justify-content: center;
  margin: 0 auto;
}
#left {
  min-width: 50%;
}
#right {
  margin-left: 10px;
}
.job-title {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.resume-row {
  display: flex;
  justify-content: space-between;
  flex: 0 0;
  align-items: center;
  padding: 10px;
  background: rgb(235, 235, 235);
  border-radius: 25px;
  margin: 10px 0;
}
.resume-row > div {
  margin-right: 20px;
}
.fontstyle {
  font-weight: bold;
}
.resume-row-mid {
  color: gray;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding-left: 20px;
  flex-grow: 1;
}
.avatar {
  width: 80px;
  height: 80px;
  border-radius: 40px;
}
</style>